<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    span{
      padding-left: 15px;
      background: url('../webapi-day01/images/mess.png') no-repeat;
      background-position-y: 3px;
      color:#333;
      vertical-align: middle;
    }
    .wrong {
      color: red;
      background: url('../webapi-day01/images/wrong.png') no-repeat;
    }
  </style>
</head>
<body>
  <input type="text"><span>请输入6-16位内容</span>

  <script>
    var input = document.querySelector('input')
    var span = document.querySelector('span')

    input.onblur =  function(){  // 失去焦点   
      if( this.value.length < 6 || this.value.length > 16 ) {
        span.className = 'wrong'
      } else {
        span.className = ''
      }
    } 

    // 获得焦点  onfocus
    // 鼠标移入   onmouseover
    // 鼠标离开   onmouseout
  </script>
</body>
</html>